<?xml version="1.0" encoding="ISO-8859-1"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">	

	<xsl:template match="/table">
		<xsl:apply-templates />
	</xsl:template>
	
	<xsl:template match="/table">
	
		<xsl:element name="identification">
		
			<xsl:for-each select="/table/body/tr/td">
				
				<xsl:if test="position() = 2">					
					<xsl:element name="re-number">
						<xsl:value-of select="normalize-space(.)" />
					</xsl:element>
				</xsl:if>
				
				<xsl:if test="position() = 4">					
					<xsl:element name="status">
						<xsl:value-of select="normalize-space(.)" />
					</xsl:element>
				</xsl:if>
				
				<xsl:if test="position() = 6">
					<xsl:element name="exporter-cpf-cnpj">					
						<xsl:value-of select="normalize-space(.)" />
					</xsl:element>
				</xsl:if>
				
				<xsl:if test="position() = 8">
					<xsl:element name="exporter-name">
						<xsl:value-of select="normalize-space(.)" />					
					</xsl:element>
				</xsl:if>
				
				<xsl:if test="position() = 10">
					<xsl:variable name="lastUpdateDay" select="substring(normalize-space(.), 0, 3)" />
					<xsl:variable name="lastUpdateMonth" select="substring(normalize-space(.), 4, 2)" />
					<xsl:variable name="lastUpdateYear" select="substring(normalize-space(.), 7, 4)" />
					<xsl:variable name="lastUpdateTime" select="substring(normalize-space(.), 14, 8)" />
					<xsl:element name="last-update">
						<xsl:value-of select="concat($lastUpdateYear, '-', $lastUpdateMonth, '-', $lastUpdateDay, 'T', $lastUpdateTime)" />
					</xsl:element>				
				</xsl:if>
				
				<xsl:if test="position() = 12">
					<xsl:variable name="recordDateDay" select="substring(normalize-space(.), 0, 3)" />
					<xsl:variable name="recordDateMonth" select="substring(normalize-space(.), 4, 2)" />
					<xsl:variable name="recordDateYear" select="substring(normalize-space(.), 7, 4)" />
					<xsl:variable name="recordDateTime" select="substring(normalize-space(.), 14, 8)" />
					<xsl:element name="record-date">					
						<xsl:value-of select="concat($recordDateYear, '-', $recordDateMonth, '-', $recordDateDay, 'T', $recordDateTime)" />					
					</xsl:element>
				</xsl:if>
						
			</xsl:for-each>
			
		</xsl:element>
		
	</xsl:template>
	
</xsl:stylesheet>


